<%-- 
    Document   : administracaoPerfilListar
    Created on : 21/10/2010, 10:28:31
    Author     : Thiago
--%>

<%@page import="dao.*"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="crypt.Crypt"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="bo.*"%>
<%@page import="beans.*"%>
<%@page import="autenticacao.Sessao"%>
<%
            String moduleId = "22";
            Crypt crypt = new Crypt();
            try {
                crypt.setKey(crypt.Decifragem((String) session.getAttribute("userPhrase")));
                String desafio = crypt.Cifragem(moduleId + "@" + ferramentas.DataHora.formatarDataHora(ferramentas.DataHora.retornarDataHoraAtual(), ferramentas.DataHora.DATE_TIME_FORMAT));
                if (!(new Sessao(session).validarSessao(desafio))) {
                    response.sendRedirect("/" + request.getContextPath());
                }
            } catch (Exception e) {
                response.sendRedirect("/" + request.getContextPath());
            }

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Gestor Operacional</title>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/style.css" type="text/css" rel="stylesheet"/>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/table.css" type="text/css" rel="stylesheet"/>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/anytime.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/jquery.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/anytime.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/anytimetz.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/table.js"></script>
    </head>
    <body>
        <table width="100%">
            <tr>
                <td>
                    <jsp:include page = "../menu.jsp" flush = "true"/>
                </td>
            </tr>

            <tr align="center">
                <td><br/><br/>
                    <input type="hidden" name="exibirGrafico" value="true">
                    <table border="1" cellspacing="0" width="430" bgcolor="#FFFFFF">
                        <tr>
                            <td width="105">
                                <div class="widget_tableDiv">
                                    <table id="myTable">
                                        <thead align="center">
                                            <tr>
                                                <td align="center"><b>Código</b></td>
                                                <td align="center"><b>Descrição</b></td>
                                                <td align="center"><b>Status</b></td>
                                                <td align="center"><b>Módulos</b></td>
                                            </tr>
                                        </thead>
                                        <tbody class="scrollingContent">
                                            <%
                                                        ArrayList<Perfil> plist = null;
                                                        try {
                                                            plist = new PerfilDAO().recuperarPerfils(null);
                                                        } catch (Exception e) {
                                                            System.out.println(e.getMessage());
                                                        }
                                                        if ((plist != null) && (!plist.isEmpty())) {
                                                            for (int i = 0; i < plist.size(); i++) {
                                                                out.println("<tr>");

                                                                out.println("<td align=\"center\"><a href=\"administracaoPerfilEditar.jsp?perfil=" + plist.get(i).getId() + "\">" + plist.get(i).getId() + "</a></td>");

                                                                out.println("<td>&emsp;&emsp;" + plist.get(i).getDescricao() + "</td>");

                                                                String aux = "";
                                                                if (plist.get(i).getStatus() == Perfil.ATIVO) {
                                                                    aux = "Ativo";
                                                                } else {
                                                                    aux = "Inativo";
                                                                }
                                                                out.println("<td align=\"center\">" + aux + "</td>");

                                                                ModuloPerfil mp = new ModuloPerfil();
                                                                mp.setPerfil(plist.get(i));

                                                                ArrayList<ModuloPerfil> amp = new ModuloPerfilDAO().recuperarModPerfil(mp);

                                                                out.println("<td>");
                                                                if ((amp != null) && (!amp.isEmpty())) {
                                                                    out.println("<ul>");
                                                                    for (int j = 0; j < amp.size(); j++) {
                                                                        if ((amp.get(j) != null) && (amp.get(j).getModulo() != null)) {
                                                                            out.println("<li>"+amp.get(j).getModulo().getGrupo()+" - "+amp.get(j).getModulo().getSubGrupo()+" - "+amp.get(j).getModulo().getDescricao()+"</li>");
                                                                        }
                                                                    }
                                                                    out.println("</ul>");
                                                                }
                                                                out.println("</td>");
                                                                out.println("</tr>");
                                                            }
                                                        }
                                            %>
                                        </tbody>
                                    </table>
                                </div>
                                <script type="text/javascript">
                                    initTableWidget('myTable',700,350,Array('S','S','S','S'));
                                </script>
                            </td>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
